package day06;

import java.util.Scanner;

public class Hotel {

	static String[][] rooms = new String[10][12];

	public static void main(String[] args) {
		// ctrl + 1, 对报错代码快速修复快捷键
		menu();
	}

	// 主菜单
	private static void menu() {

		//		Scanner sc = new Scanner(System.in);
		//		String str = sc.nextLine();
		//		switch(str) {}

		// 将目标代码框选起来
		// alt + shift + z, 调出快捷菜单
		// 选择要包裹的语法结构
		while (true) {
			System.out.println("1. 查看客房状态");
			System.out.println("2. 办理入住");
			System.out.println("3. 办理退房");
			System.out.println("0. 退出程序");
			System.out.println("请选择");
			switch (new Scanner(System.in).nextLine()) {
				case "1":
					show();
					break;
				case "2":
					checkin();
					break;
				case "3":
					checkout();
					break;
				case "0":
					System.out.println("再见!");
					return;
				default:
					System.out.println("选择错误");
			}
		}

	}

	// 办理退房
	private static void checkout() {
		// 提示并接收选择房间
		System.out.println("请选择房间");
		int x = new Scanner(System.in).nextInt();

		// 判断所选房间是否有效
		int r = x / 100 - 1;
		int c = x % 100 - 1;
		if (r < 0 || r > rooms.length - 1 || c < 0 || c > rooms[r].length - 1) {
			System.out.println("所选房间无效");
			return;
		}

		// 判断所选房间是否为空
		if (rooms[r][c] == null) {
			System.out.println("所选房间无人入住");
			return;
		}

		rooms[r][c] = null;
		System.out.println("退房成功");
	}

	// 办理入住
	private static void checkin() {

		// 提示并接收选择房间
		System.out.println("请选择房间");
		int x = new Scanner(System.in).nextInt();

		// 判断所选房间是否有效
		int r = x / 100 - 1;
		int c = x % 100 - 1;
		if (r < 0 || r > rooms.length - 1 || c < 0 || c > rooms[r].length - 1) {
			System.out.println("所选房间无效");
			return;
		}

		// 判断所选房间是否为空
		if (rooms[r][c] != null) {
			System.out.println("所选房间已有人入住");
			return;
		}

		// 录入客人姓名存入到房间中
		System.out.println("请输入客人姓名");
		String name = new Scanner(System.in).nextLine();
		rooms[r][c] = name;
		System.out.println("入住成功");

	}

	// 查看客房状态
	private static void show() {

		for (int i = 0; i < rooms.length; i++) {
			for (int j = 0; j < rooms[i].length; j++) {
				String r = (i + 1 <= 9 ? "0" : "") + (i + 1);
				String c = (j + 1 <= 9 ? "0" : "") + (j + 1);
				System.out.print(r + c + "\t");
			}
			System.out.println();
			for (int j = 0; j < rooms[i].length; j++) {

				System.out.print((rooms[i][j] == null ? "空闲" : rooms[i][j]) + "\t");

			}
			System.out.println("\r\n");
		}

	}

}
